package com.qwqk.controller;
    
    




import com.anwen.mongo.conditions.query.LambdaQueryChainWrapper;
import com.anwen.mongo.model.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.qwqk.entity.Idcards;
import com.qwqk.service.IdcardsService;
import com.qwqk.config.Result;

/**
 * 控制层
 *
 * @author makejava
 * @since 2024-08-29 13:59:53
 */
@RestController
@Slf4j
@Api(tags = "Idcards类")
@RequestMapping("/idcards")
public class IdcardsController {
    @Resource
	private IdcardsService idcardsService;
    

    @GetMapping("/")
    @ApiOperation("查询所有Idcards")
    public Result<List<Idcards>> findAll(){
        List<Idcards> list = idcardsService.list();
        return Result.success(list);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询所有Idcards")
    public Result<PageResult<Idcards>> findAllUser(Integer pageNum, Integer pageSize){
        LambdaQueryChainWrapper<Idcards> queryChainWrapper = idcardsService.lambdaQuery();
        PageResult<Idcards> page = idcardsService.page(queryChainWrapper, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询一条Idcards数据")
    public Result<Idcards> findAll(@PathVariable("id") String id){
        Idcards one =  idcardsService.getById(id);
        return Result.success(one);
    }

    @PostMapping("/")
    @ApiOperation("添加Idcards")
    @Transactional
    public Result addUser(@RequestBody Idcards idcards){
        idcardsService.save(idcards);
        return Result.success();
    }


    @PutMapping("/")
    @ApiOperation("根据id修改Idcards")
    public Result updateUserById(@RequestBody Idcards idcards){
        idcardsService.updateById(idcards);
        return Result.success();
    }



    @DeleteMapping ("/{id}")
    @ApiOperation("根据id删除Idcards")
    public Result deleteUserById(@PathVariable("id")String id){
        idcardsService.removeById(id);
        return Result.success();
    }


}
